import styles from './index.module.scss'
import Dialog from '@c/dialog'
import { useSetUserInfo } from '@/utils/hooks'
import Button from '@c/button'
import dayjs from 'dayjs'
import { useEffect, useState } from 'react'

const Index = ({ onClose,user,day }) => {
  const [date,setDate] = useState('')
  const [_, setUserInfo] = useSetUserInfo()
  const close = () => {
    setUserInfo(localStorage.getItem('token'))
    onClose()
  }

  useEffect(() =>{
    let date = ''
    if(!user.isVip){
      date = dayjs().add(day,'day')
    }else{
      date = dayjs().add(1+day+user.vipDay,'day')
    }
    setDate(date.format('YYYY年MM月DD日'))
  },[])

  return (
    <Dialog className={styles.content}>
      <div className={styles.bg}>
        <p className={styles.title}>会员兑换成功！</p>
        <p className={styles.tips}>会员有效期至{date}</p>
        <Button className={styles.sureBtn} onClick={close} >
          确定
        </Button>
      </div>
    </Dialog>
  )
}

export default Index
